home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / WINPROGS / IWF12.ZIP / MODULES / RENDER.C < prev    next >
C/C++ Source or Header  |  1994-02-20  |  14KB  |  448 lines

  1. /*
  2. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3. PROFIL3.C (PROFILE procedures)
  4.  
  5.  
  6. AUTHOR(s): Craig Muller 1992
  7.  
  8. Decription:
  9.  
  10. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  11. */
  12. #include <windows.h>
  13.  
  14. #pragma hdrstop
  15.  
  16. #include <stdio.h>
  17. #include <string.h>
  18. #include "iwf.h"
  19.  
  20. // Defines.
  21. #define  MODULENAME "Render"
  22. #define  CLASSNAME  MODULENAME"Popup"
  23.  
  24. //=======================================
  25. // Exported procedures.
  26. //=======================================
  27. long far PASCAL _export WP_Render(HWND hWnd,WORD wMsg,WORD wParam,LONG lParam);
  28. BOOL FAR PASCAL _export DP_Render(HWND hDlg,WORD wMsg,WORD wParam,LONG lParam);
  29.  
  30. //-------------------------------------
  31. // Private procedures.
  32. //-------------------------------------
  33. void CreateThermoPalEntry(PALETTEENTRY *peThermo);
  34. static void render(HDC hDC,IMAGE *image);
  35.  
  36. // Flags
  37.  
  38. // Private variables.
  39. static int resolutions[]={1,2,5,10};
  40. static int polyres =3;
  41. static int usecolor=TRUE;
  42. static int usegrid =TRUE;
  43.  
  44. static HPALETTE hPalColor;             // Handle to color scale palette
  45.  
  46. static HWND hWndRender=NULL;           // Render user window handle.
  47.  
  48. static HINSTANCE hInst;                  // Application instance handle.
  49.  
  50. /*
  51. ---------------------------------------------------------------------
  52. fb_setpalette()
  53. ~~~~~~~~~~~~~~~~
  54.  
  55. DESCRIPTION:
  56. ---------------------------------------------------------------------
  57. */
  58. void fb_SetPaletteEntries(IMAGE *image,int iStart,int cEntries,PALETTEENTRY *pe)
  59.     {
  60.     int i;
  61.  
  62.     for (i=0; i<cEntries; i++)
  63.         {
  64.         image->LUT[iStart+i].peRed   = pe[i].peRed;
  65.         image->LUT[iStart+i].peGreen = pe[i].peGreen;
  66.         image->LUT[iStart+i].peBlue  = pe[i].peBlue;
  67.         image->LUT[iStart+i].peFlags = pe[i].peFlags;
  68.         }
  69.     }
  70.  
  71. /*
  72. --------------------------------------------------------------------------
  73. Render()
  74. ~~~~~~~~
  75.  
  76. PROFILER STARTUP PROCESSING PROCEDURE.
  77. This is called when the user selects this option from the main menu.
  78. This procedure check to see if the popup window exists. If so it simply
  79. passes focus to the window and returns since there is nothing more to do.
  80. If it does not exist then it proceeds to create the popup window and menu
  81. and displays it on the screen. The popup window acts like a sub-program
  82. within the main program and receives messages from the main program.
  83. --------------------------------------------------------------------------
  84. */
  85. void Render(HWND hWndParent)
  86.    {
  87.    char   msg[80];
  88.    WNDCLASS  wc;
  89.  
  90.    // If an instance exists then set focus to that instance and return.
  91.    if (IsWindow(hWndRender))
  92.       {
  93.       ShowWindow(hWndRender,SW_SHOW);
  94.       SetFocus(hWndRender);
  95.       return;
  96.       }
  97.  
  98.    hInst = GetWindowWord(hWndParent,GWW_HINSTANCE);
  99.  
  100.    // Register a new window class for the popup window.
  101.    if (!GetClassInfo(hInst,CLASSNAME,&wc))
  102.       {
  103.       memset(&wc,0,sizeof(WNDCLASS));            // Zero init structure.
  104.  
  105.       wc.lpszClassName = CLASSNAME;              // Name for CreateWindow.
  106.       wc.style         = CS_SAVEBITS;            // Extra style parameters.
  107.       wc.lpfnWndProc   = (WNDPROC)WP_Render;     // Func to get msgs
  108.       wc.hInstance     = hInst;                  // App that owns the class
  109.       wc.hIcon         = LoadIcon(hInst,MODULENAME);
  110.       wc.lpszMenuName  = MODULENAME;
  111.       wc.hbrBackground = GetStockObject(LTGRAY_BRUSH);
  112.  
  113.       if (!RegisterClass(&wc))                   // Initialize new window class.
  114.          {
  115.          char sz[80];
  116.  
  117.          sprintf(sz,"RegisterClass() failure! -> %s",CLASSNAME);
  118.          MessageBeep(MB_ICONEXCLAMATION);
  119.          MessageBox(NULL,sz,NULL,MB_OK | MB_ICONEXCLAMATION);
  120.          return;                                 // Exit on failure
  121.          }
  122.       }
  123.  
  124.    // Window class is registered, now create an window from the class.
  125.    hWndRender = CreateWindow(CLASSNAME,MODULENAME,
  126.                              WS_POPUPWINDOW | WS_CAPTION | WS_MINIMIZEBOX,
  127.                             200,100,770,400,hWndParent,NULL,hInst,NULL);
  128.    if (hWndRender)
  129.       {
  130.       ShowWindow(hWndRender,SW_SHOW);
  131.       SetFocus(hWndRender);
  132.       }
  133.    else
  134.       {
  135.       sprintf(msg,"CreateWindow() failure! -> %s",CLASSNAME);
  136.       MessageBeep(MB_ICONEXCLAMATION);
  137.         MessageBox(NULL,msg,NULL,MB_OK | MB_ICONEXCLAMATION);
  138.       }
  139.    }
  140.  
  141.  
  142.  
  143. /*
  144. ---------------------------------------------------------------------
  145. long far PASCAL _export WP_Render(HWND hWnd,WORD wMsg,WORD wParam,LONG lParam);
  146.  
  147. Description:
  148.  
  149. Local Window Procedure for processing image analysis. This is
  150. registered in the header module.h.
  151.  
  152. This procedure handles a subset of the Windows message loop for
  153. processing input messages.
  154. ---------------------------------------------------------------------
  155. */
  156. long far PASCAL _export WP_Render(HWND hWnd,WORD wMsg,WORD wParam,LONG lParam)
  157.    {
  158.    IMAGE *image;
  159.  
  160.    if (IsWindow(hWndSrc))
  161.       image = (IMAGE *)GetWindowWord(hWndSrc,2);       // Get attached data set.
  162.    else
  163.       image = NULL;
  164.  
  165.    switch (wMsg)
  166.       {
  167.       case WM_CREATE:
  168.       hWndMod = hWnd;                            // Make this module active.
  169.       break;
  170.  
  171.       case WM_PAINT:
  172.       {
  173.       PAINTSTRUCT ps;
  174.  
  175.       BeginPaint(hWnd,&ps);
  176.       EndPaint(hWnd,&ps);
  177.       }
  178.       break;
  179.  
  180.       case WM_COMMAND:
  181.       if (!image)
  182.          {
  183.          MessageBox(NULL,"No image is selected.","Render Tool",MB_OK);
  184.          break;
  185.          }
  186.  
  187.       switch (wParam)
  188.           {
  189.          case 110:
  190.          {
  191.          RECT rc;
  192.          HDC hDC;
  193.  
  194.          hDC = GetDC(hWnd);
  195.          SelectPalette(hDC,hPalMain,FALSE);       // Select palette into DC
  196.          RealizePalette(hDC);                    // Map to system palette.
  197.  
  198.            GetClientRect(hWnd,&rc);
  199.            FillRect(hDC,&rc,GetStockObject(LTGRAY_BRUSH));
  200.          render(hDC,image);                      // Render the 3D profile.
  201.  
  202.          ReleaseDC(hWnd,hDC);
  203.          }
  204.          break;
  205.  
  206.           case 120:
  207.          CallDialogBox(hWnd,DP_Render,MODULENAME);
  208.          break;
  209.          }
  210.       break;
  211.  
  212.       case WM_SETFOCUS:                          // FOCUS HAS BEEN SET.
  213.       if (FlashWindow(hWnd,TRUE))
  214.          FlashWindow(hWnd,TRUE);                 // Make this module active.
  215.       hWndMod = hWnd;                            // Make this module active.
  216.       BringWindowToTop(hWnd);                    // Bring this module to top.
  217.       InvalidateRect(hWnd,NULL,FALSE);           // Invalidate this image.
  218.       UpdateWindow(hWnd);                        // Update this image.
  219.       break;
  220.  
  221.       case WM_KILLFOCUS:                         // FOCUS HAS BEEN KILLED.
  222.       break;
  223.  
  224.       case WM_DESTROY:                           // DESTROY WINDOW.
  225.       DeleteObject(hPalColor);                   // Delete color scale palette.
  226.       break;
  227.  
  228.       default:                                   // Pass on if unprocessed.
  229.       return(DefWindowProc(hWnd, wMsg, wParam, lParam));
  230.       }
  231.  
  232.    lParam=lParam;
  233.  
  234.    return(NULL);
  235.    }
  236.  
  237.  
  238. void Project(int x,int y,int z,POINT *pt)
  239.    {
  240.    pt->x = 240 + x - y/2;
  241.    pt->y = y/2 - z/2;
  242.    }
  243.  
  244. /*
  245. ------------------------------------------------------------------------------
  246. FUNCTION: void Render(HWND hWnd)
  247.  
  248. PURPOSE :
  249. Transfers the contents to the display device for display.
  250.  
  251. COMMENTS:
  252. ------------------------------------------------------------------------------
  253. */
  254. void render(HDC hDC,IMAGE *image)
  255.    {
  256.    int         size,x,y,xoff,yoff;
  257.    BYTE        r,g,b,z,z0,z1,z2,z3;
  258.    POINT       pt[4];
  259.    HBRUSH      hBrush,hOldBrush;
  260.    HPEN        hPen,hOldPen;
  261.  
  262.    ShowCursor(FALSE);
  263.  
  264.    size=resolutions[polyres];
  265.    xoff = 3;
  266.    yoff = 375-240;
  267.    SelectObject(hDC,GetStockObject(BLACK_PEN));
  268.  
  269.    Project(  0,  0,  0,&pt[0]);  MoveTo(hDC,xoff+pt[0].x,yoff+pt[0].y);
  270.    Project(511,  0,  0,&pt[0]);  LineTo(hDC,xoff+pt[0].x,yoff+pt[0].y);
  271.    Project(511,479,  0,&pt[0]);  LineTo(hDC,xoff+pt[0].x,yoff+pt[0].y);
  272.    Project(  0,479,  0,&pt[0]);  LineTo(hDC,xoff+pt[0].x,yoff+pt[0].y);
  273.    Project(  0,  0,  0,&pt[0